home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / system / dosmnu70.zip / NOBRK.EXE / NOBRK.ASM next >
Assembly Source File  |  1988-04-04  |  7KB  |  322 lines

  1.     name    BRK
  2.     page    55,132
  3.     title    'CTRL-BRK and CTRL-C disble and enable controller'
  4.  
  5. COMMENT @
  6.  
  7.   COPYRIGHT (c) John Pulliam, Walter Cox, Benjamin J. Diss 
  8.                 October 15, 1987, April 4, 1988
  9.  
  10.     This is a simple device driver that disables the Ctrl-C and
  11.   Ctrl-Break interrupts.  It may be toggled on or off by sending the word 'on'
  12.   or the word 'off' to the driver.  The driver is installed with the name
  13.   'ctrl-brk'.  
  14.  
  15.   ex.
  16.  
  17.   copy con ctrl-brk
  18.   off
  19.   ^Z
  20.  
  21.               1 file(s) copied
  22.  
  23.   To assist in communicating with the driver a utility called nobrk is included.
  24.   It will send the command tail to the driver called 'ctrl-brk'.
  25.  
  26.   The driver operates by intercepting all keystokes and looking for ctrl-brk
  27.   and ctrl-c.  If active it will intercept them, it not active it passes the
  28.   keystokes to the appropriate handler.
  29.  
  30.   This program is provided "AS IS" and the authors assume NO LIABILITY
  31.   for damages from the use of this program.
  32.  
  33.      For DOS 2.0 +.
  34. @
  35.  
  36.  
  37. code    segment    public    'CODE'
  38.  
  39. driver    proc    far
  40.  
  41.     assume    cs:code,ds:code,es:code
  42.  
  43.     org    0
  44.  
  45. ctrl    equ    04h        ; Ctrl Key is Depressed
  46.  
  47. seg40    equ    40h        ; Keyboard buffer segment
  48. kbflag    equ    17h        ; Offset of KBFLAG in SEG 40H
  49. kbinctl    equ    60h        ; Keyboard IN port address
  50. kbcmdp    equ    61h        ; Keyboard COMMAND port address
  51.  
  52.  
  53. init_cmd    equ    0
  54. read_cmd    equ    4
  55. write_cmd    equ    8
  56.  
  57. cr    equ    0dh
  58. lf    equ    0ah
  59. eom    equ    '$'
  60.  
  61. ;
  62. ;    device driver header
  63. ;
  64.  
  65. header    dd    -1    ; link to next device, -1 = end of list
  66.  
  67.     dw    8000h    ; device Attribute Word
  68.     dw    strat    ; device stratagy entry point
  69.     dw    intr    ; device interrupt entry point
  70.     db    'CTRL-BRK'    ; character device name
  71.  
  72. rh_ptr    dd    ?
  73.     page
  74.  
  75. dispatch:
  76.     dw    init
  77.     dw    write
  78.  
  79. request struc
  80.  
  81. rlength    db    ?
  82. unit    db    ?
  83. command    db    ?
  84. status    dw    ?
  85. reserve    db    8 dup (?)
  86. media    db    ?
  87. address    dd    ?
  88. count    dw    ?
  89. sector    dw    ?
  90.  
  91. request    ends
  92.     page
  93.  
  94. msg_len    dw    ?
  95.  
  96. flag    db    1        ; NOBRK turned ON or OFF (1 = ON, 0 = OFF)
  97. kbseg    dw    SEG40        ; Keyboard Segment
  98. int09:    dw    0,0        ; Store KBD BIOS interrupt 09 hex vector here
  99.  
  100. strat    proc    far
  101.  
  102.     mov    word ptr cs:[rh_ptr],bx
  103.     mov    word ptr cs:[rh_ptr+2],es
  104.     ret
  105.  
  106. strat    endp
  107.  
  108.     page
  109.  
  110. intr    proc    far
  111.  
  112.     push    ax    ; save general registers
  113.     push    bx
  114.     push    cx
  115.     push    dx
  116.     push    ds
  117.     push    es
  118.     push    di
  119.     push    si
  120.     push    bp
  121.  
  122.     push    cs    ; make local data addressable
  123.     pop    ds
  124.  
  125.     les    di,[rh_ptr]    ; let es:di = request header
  126.  
  127.     mov    bl,es:[di.command]    ; get bx = command code
  128.     xor    bh,bh
  129.  
  130.     cmp    bx,init_cmd    ; check for init command
  131.     je    intr1
  132.  
  133.     cmp    bx,read_cmd    ; check for read command
  134.     jne    test_write
  135.     mov    ax,800bh
  136.     jmp    intr2
  137.  
  138. test_write:    cmp    bx,write_cmd    ; check for write command
  139.     jne    cmd_error
  140.     mov    bx,1
  141.     jmp    intr1
  142.  
  143. cmd_error:    mov    ax,8003h    ; set error bit and unknown command code
  144.     jmp    intr2
  145.  
  146. intr1:    shl    bx,1    ; form index to dispatch table
  147.     call    word ptr [bx+dispatch]    ; and branch to driver routine
  148.             ; should return ax=status
  149.     les    di,[rh_ptr]    ; restore es:di = addr of request header
  150.  
  151. intr2:    or    ax,0100h    ; merge done bit into status, and
  152.     mov    es:[di.status],ax    ; store into request header
  153.  
  154.     pop    bp
  155.     pop    si
  156.     pop    di
  157.     pop    es
  158.     pop    ds
  159.     pop    dx
  160.     pop    cx
  161.     pop    bx
  162.     pop    ax
  163.     ret        ; back to dos
  164.  
  165.     page
  166.  
  167. write    proc    near
  168.  
  169.     mov    dx,es:[di]+14    ; offset of string
  170.     mov    ds,es:[di]+16    ; segment of string
  171.     mov    cx,es:[di]+18    ; number of bytes in string
  172.  
  173.     mov    cs:msg_len,cx    ; store number of bytes on stack
  174.     cld
  175.  
  176.     push    ds
  177.     pop    es
  178.  
  179.     mov    di,dx
  180.     mov    al,'F'    ; look in string for 'F'
  181. repne    scasb        ; set cf = 0 if found, 1 if not
  182.     je    brk_off    ; jump if cf = 0
  183.  
  184.     mov    di,dx
  185.     mov    al,'f'    ; look in string for 'f'
  186.     mov    cx,cs:msg_len    ; restore number of bytes
  187. repne    scasb        ; set cf = 0 if found, 1 if not
  188.     je    brk_off    ; jump if cf = 0
  189.  
  190.     mov    di,dx
  191.     mov    al,'N'    ; look in string for 'N'
  192.     mov    cx,cs:msg_len    ; restore number of bytes
  193. repne    scasb        ; set cf = 0 if found, 1 if not
  194.     je    brk_on    ; jump if cf = 0
  195.  
  196.     mov    di,dx
  197.     mov    al,'n'    ; look in string for 'n'
  198.     mov    cx,cs:msg_len    ; restore number of bytes
  199. repne    scasb        ; set cf = 0 if found, 1 if not
  200.     je    brk_on    ; jump if cf = 0
  201.     jmp    done
  202.  
  203. brk_on:    mov    cs:flag,0
  204.     jmp    done
  205.  
  206. brk_off:    mov    cs:flag,1
  207.  
  208. done:    xor    ax,ax
  209.     ret
  210.  
  211. write    endp
  212.  
  213. chkkey:    pushf        ; Save all registers
  214.     push    ax
  215.     push    cx
  216.     push    di
  217.     push    si
  218.     push    ds
  219.     push    es
  220.     sti        ; Allow other interrupts to occur
  221.  
  222.     mov    ax,cs
  223.     mov    ds,ax    ; Set DS to this segment
  224.     mov    es,word ptr cs:kbseg    ; Set ES to segment of keyboard buffer
  225.     mov    si,kbflag    ; 40:17H Where DOS keeps track of shift state
  226.     mov    ah,es:[si]    ; Get key input
  227.  
  228. ; If OFF, then skip to exit, else see if we need to kill the Ctrl-C
  229. ;    (AH contains the latest KBFLAG value)
  230.  
  231.     test    cs:flag,1    ; Ignore Ctrl-C or Ctrl-Break ?
  232.     jz    exit    ; Branch if OFF
  233.  
  234.     test    ah,ctrl    ; Is Control Key pressed?
  235.     jz    exit    ; No, pass the key to BIOS routine
  236.     test    ah,0bh    ; Is ALT, LEFT or RIGHT SHIFT pressed ?
  237.     jnz    exit    ; No, pass the key to BIOS routine
  238.  
  239.     in    al,kbinctl    ; Get the key code
  240.     cmp    al,46    ; ^C?
  241.     je    kill    ; Yes, kill it
  242.     cmp    al,70    ; ^BREAK?
  243.     jne    exit    ; No, exit to BIOS
  244.  
  245. ;----- Kill ^C or ^BREAK
  246.  
  247. kill:    in    al,kbcmdp    ; Read the KB command port
  248.     mov    ah,al    ; Copy it to AH
  249.     or    al,80h    ; Set RESET bit
  250.     out    kbcmdp,al    ; Write RESET to the command port
  251.     mov    al,ah    ; Clear the RESET bit
  252.     out    kbcmdp,al    ; and write to the command port
  253.     mov    al,20h    ; Send END OF INTERRUPT to the interrupt cont.
  254.     out    20h,al
  255.  
  256.     pop    es    ; Restore all registers
  257.     pop    ds
  258.     pop    si
  259.     pop    di
  260.     pop    cx
  261.     pop    ax
  262.     popf
  263.     iret        ; Return to the interrupted routine
  264.  
  265.  
  266. ; Restore registers and exit to the DOS keyboard interrupt handler
  267.  
  268. exit:    pop    es    ; Restore all registers
  269.     pop    ds
  270.     pop    si
  271.     pop    di
  272.     pop    cx
  273.     pop    ax
  274.     popf
  275.     jmp    dword ptr cs:int09    ; Exit to BIOS keyboard interrupt routine
  276.  
  277.  
  278. init    proc    near
  279.  
  280.     push    es    ; save address of request header
  281.     push    di
  282.  
  283.     mov    ax,3509h    ; Get Interrupt Vector function
  284.     int    21h    ; Execute DOS function
  285.     mov    word ptr int09,bx    ; Store BIOS offset for INT 09
  286.     mov    word ptr int09+2,es    ; Store BIOS segment for INT 09
  287.     mov    dx,offset chkkey    ; New INT 09 vector
  288.     mov    ax,2509h    ; Set Interrupt Vector function
  289.     int    21h    ; Execute DOS function
  290.  
  291.     mov    ah,9    ; print sign-on message
  292.     mov    dx,offset message
  293.     int    21h
  294.  
  295.     pop    di    ; restore request header addr
  296.     pop    es
  297.  
  298.     mov    word ptr es:[di.address],offset init
  299.     mov    word ptr es:[di.address+2],cs
  300.  
  301.     xor    ax,ax
  302.     ret
  303.  
  304. init    endp
  305.  
  306. message    db    cr,lf
  307.     db    'CTRL-BRK - A device driver to intercept ctrl-brk and ctrl-c.'
  308.     db    cr,lf
  309.     db    '(C) 1987, 1988 John Pulliam, Walter Cox, and Benjamin Diss.'
  310.     db    cr,lf,lf,eom
  311.  
  312. intr    endp
  313.  
  314.     page
  315.  
  316. driver    endp
  317.  
  318. code    ends
  319.  
  320.     end
  321.  
  322.